<template>
	<b-layout-index>
		<theme-color-bg type="c3">
		<navbar  :isStyle="light" :title="$t('账户金额')"></navbar>
			
		<view class="pd-20 text-center">
			<view class="font-size-30   font-bold">{{info.balance}}￥</view>
			<view class="font-size-14  ">{{$t('总额')}}</view>
		</view>
		</theme-color-bg>
		<view class="pd-top-20 pd-bottom-20 bg-white  text-center">
			<u-grid :border="false" @click="click" col="2">

				<u-grid-item v-for="(baseListItem,baseListIndex) in baseList" :key="baseListIndex">

					<text class="font-size-18 u-error  font-bold">{{baseListItem.price}}￥</text>
					<text class="grid-text font-size-14">{{baseListItem.title}}</text>

				</u-grid-item>
			</u-grid>
		</view>

		<view class="mg-5  bg-white br-rd-10 ">
			<u-cell-group>
				<block v-for="(item,index) in jiluList">
					<u-cell :url="item.url" :title="item.name" :value="$t('查询')" isLink>
					</u-cell>
				</block>

			</u-cell-group>
		</view>


		<view class="mg-top-10 pd-20" >
			<u-button @click="goWithdrawal" :disabled="info.balance<=0 || info.withdrawalWaits>0" :color="color.primary" :loadingText="info.withdrawalWaits>0?$t('提现中'):$t('提现')"  :loading="(info.withdrawalWaits>0)" shape="circle" type="primary">
				{{$t('去提现')}}
			</u-button>
		</view>

	</b-layout-index>
</template>

<script>
	import {
		findByInfo
	} from "@/api/userWallet.js"
	export default {
		data() {
			return {
				baseList: [],
				jiluList: [{
						name: this.$t('提现记录'),
						url: "./withdrawallog"
					},
					{
						name: this.$t('余额明细'),
						url: "./accountbook"
					}
				],
				info: {
					balance: 0,
					withdrawal: 0,
					withdrawalWaits: 0
				}
			}
		},
		onLoad: function() {

		},
		onShow: function() {
			this.getInfo()
		},
		methods: {
			click(name) {
				this.$refs.uToast.success(`点击了第${name}个`)
			},
			goWithdrawal: function(e) {
				var info = this.info;
				if (info.withdrawalWaits >= 0) {
					uni.navigateTo({
						url: "./withdrawal"
					})
				} else {
					uni.showToast({
						title: this.$t("提现中"),
						icon: "error"
					})
				}
				//console.log(e)
			},
			getInfo: function() {
				findByInfo().then(res => {
					this.info = res
					uni.setStorageSync("userWalletFindByInfo", res)

					this.baseList = [{
							price: res.withdrawal,
							title: this.$t('累计提现')

						},
						{
							price: res.withdrawalWaits,
							title: this.$t('提现中'),
						}

					]
				})
			}
		}
	}
</script>

<style>
</style>
